<?php
namespace Home\Controller;
use Think\Controller;
class MovieController extends IndexController {
    var $movie;

    function __construct()
    {
        parent::__construct();
        $this->movie = M('movie');
        $this->type = M('type');
        $this->style = M('style');
        $this->region = M('region');
        $this->movie_style = M('movie_style');



    }

    function index(){
        $types = $this->type->select();
        $styles = $this->style->select();
        $regions = $this->region->select();

        $region_url = $style_url = $type_url  = $_GET;
        unset($type_url['type_id']);
        unset($region_url['region_id']);
        unset($style_url['style_id']);



        $map = array();
        if(isset($_GET['type_id']) && I("get.type_id")!='') {
            $map['type_id'] = I("get.type_id");
        }
        if(isset($_GET['region_id']) && I("get.region_id")!='') {
            $map['region_id'] = I("get.region_id");
        }

        if(isset($_GET['style_id']) && I("get.style_id")!='') {
            $style_id=I("get.style_id");
            $data['style_id'] = $style_id;
            $movie_id = $this->movie_style->where($data)->getField('movie_id', true);
            $map['id'] = $movie_id ?  array('in', $movie_id) : '';
        }

        $movies = $this->movie->where($map)->select();

        $hots = $this->movie->order('view desc')->select();
        //dump($hots);

        $this->assign('type_url', $type_url);
        $this->assign('style_url', $style_url);
        $this->assign('region_url',$region_url);

        //dump($movies);exit;
        $this->assign("movies",$movies);
        $this->assign("types",$types);
        $this->assign("styles",$styles);
        $this->assign("regions",$regions);
        $this->assign("hots",$hots);


        $this->display();
    }
    function show(){
        $id = I("get.id");
        $m = $this->movie->find($id);
        //dump($movies);exit;
        $this->assign("m",$m);
        //dump($id);exit;
        $this->movie->where("id = '$id'")->setInc('view');
        $this->display();
    }
}